package com.enzo.prms.common.config;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author prms1.0
 * 
 * @date:2012-5-2 ����05:47:30
 * @version :
 * 
 */
public class ApplicationProperties {
	private String CONFIG_FILE_NAME;
	protected Properties oProperties;

	public ApplicationProperties(String sConfigFileName) {
		CONFIG_FILE_NAME = null;
		oProperties = null;
		CONFIG_FILE_NAME = sConfigFileName;
	}

	protected void loadProperties() {
		try {

			oProperties = new Properties();
			ClassLoader oClassLoader = Thread.currentThread()
					.getContextClassLoader();
			InputStream is = oClassLoader.getResourceAsStream(CONFIG_FILE_NAME
					+ ".properties");
			if (is != null) {
				oProperties.load(is);
				is.close();
			}
			// TODO why set null
			is = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getPropertyAsString(String sPropertyName, String sDefaultValue) {
		if (oProperties == null) {
			loadProperties();
		}
		return oProperties.getProperty(sPropertyName, sDefaultValue);
		// Exception e;
		// e;
		// return iDefaultValue;

	}

	public int getPropertyAsInt(String sPropertyName, int iDefaultValue) {
		String sProperty;
		if (oProperties == null) {
			loadProperties();
		}
		sProperty = oProperties.getProperty(sPropertyName);
		return Integer.parseInt(sProperty);
		// Exception e;
		// e;
		// return iDefaultValue;
	}

}
